# -*- coding: utf-8 -*-

import pika  
import sys  

parameters=pika.ConnectionParameters(  
			credentials=pika.PlainCredentials('guest', 'guest'),
        	host='127.0.0.1',
        	port=5672,
        	virtual_host='/test'
        )
connection = pika.BlockingConnection(parameters)
channel = connection.channel() 

queue_name = 'tpq'

# ------------- dome 1 --------------

def on_message(channel, method, properties, body):
    print "method : ",method
    print "properties : ",properties
    print "body : ",body
    print

channel.basic_consume(
							consumer_callback=on_message,
							queue=queue_name,  
              				no_ack=True
                    	)  
  
channel.start_consuming()  

connection.close()

# ------------- dome 2 --------------
#for method, properties, body in channel.consume(queue_name):

#    # Display the message parts
#    print "method : ", method
#    print "properties : ", properties
#    print "body : ", body
#    print

    # Acknowledge the message
#    channel.basic_ack(method_frame.delivery_tag)
